package com.fubang.pathlearning.popview;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.fubang.pathlearning.R;

/**
 * 创建者: YIN
 * 创建时间: 2017/7/27 11:44
 * 电子邮箱: yin_ruimin@foxmail.com
 * 描述:
 */

public class PopUpView extends PopupWindow implements PopupWindow.OnDismissListener {
    private Context mContext;
    private RecyclerView mListView;
    private View mInflateView;
    private CallBack listener;

    public PopUpView(Context context) {
        super(context);
        this.mContext = context;
        init();
    }


    private void init() {
        mInflateView = View.inflate(mContext, R.layout.top_popup_window, null);
        LinearLayout llContainer = (LinearLayout) mInflateView.findViewById(R.id.ll_container);
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        ColorDrawable dw = new ColorDrawable(0x80000000);
        this.setBackgroundDrawable(dw);
        setFocusable(true);
        setTouchable(true);
        setOutsideTouchable(true);
        this.setOnDismissListener(this);
        setContentView(mInflateView);
        update();
        mListView = (RecyclerView) mInflateView.findViewById(R.id.list_view);
        llContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onPopDismiss();
                }
            }
        });
    }

    public RecyclerView getListView() {
        return mListView;
    }

    public void setCallBack(CallBack listener) {
        this.listener = listener;
    }

    @Override
    public void onDismiss() {
        if (listener != null) {
            listener.onPopDismiss();
        }
    }

    public interface CallBack {
        void onPopDismiss();
    }

}
